
function hasPermission(route, roles) {
    if (route && route.meta && route.meta.permission_on) {
        return roles.some((item) => {return item == route.meta.permission_on })
    } else {
        return true;
    }
}

function filterRoutes(routes, roles) {
    var accessRoutes = routes.filter((route) => {
        if (hasPermission(route, roles)) {
            if (route.children && route.children.length > 0) {
                route.children = filterRoutes(route.children, roles)
            }
            return true;
        } else {
            return false;
        }
    })
    return accessRoutes;
}

export default filterRoutes;